package Stream_Study.comprehensive;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test3 {
    public static void main(String[] args) {
        /*
            现在有两个ArrayList集合
            第一个集合中:存储6名男演员的名字和年龄,第二个集合中:存储6名女演员的名字和年龄.
            姓名和年龄中间用逗号隔开.比如:张三,23
            要求完成如下操作:
            1.男演员只要名字为三个字的前两个人
            2.女演员只要姓杨的,并且不要第一个
            3.把过滤够的男演员和女演员姓名合并到一起
            4.将上一步的演员信息封装成Actor对象
            5.将所有的演员对象都保存到List集合中.
            备注:演员类Actor,属性只有:name,age
         */

        ArrayList<String> actor = new ArrayList<>();
        Collections.addAll(actor,"胡歌,23", "周星驰,42", "吴京,25", "刘德华,32", "张学友,34", "泰森,38");

        ArrayList<String> actress = new ArrayList<>();
        Collections.addAll(actress, "唐嫣,22", "杨洋,23", "杨紫,23", "杨幂,34", "赵丽颖,21", "迪丽热巴,25");

        List<Actor> actorList = Stream.concat(actor.stream().filter(s -> s.split(",")[0].length() == 3).limit(2),
                        actress.stream().filter(s -> s.split(",")[0].startsWith("杨")).skip(1))
                .map(s -> new Actor(s.split(",")[0], Integer.parseInt(s.split(",")[1])))
                .collect(Collectors.toList());
        System.out.println(actorList);

    }
}

class Actor{
    private String name;
    private int age;

    public Actor() {
    }

    public Actor(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "(" + name + ", " + age + ")";
    }
}
